package com.erp.tool;

import com.erp.pojo.Shoplist;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class OutExcelUtils {


    public XSSFWorkbook show(List<Shoplist>list) {
        XSSFWorkbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("shopList");//创建一张表
        Row titleRow = sheet.createRow(0);//创建第一行，起始为0
        titleRow.createCell(0).setCellValue("ID");//第一列
        titleRow.createCell(1).setCellValue("名称");
        titleRow.createCell(3).setCellValue("数量");
        titleRow.createCell(2).setCellValue("价格");
        titleRow.createCell(4).setCellValue("种类");
        int cell = 1;
        for (Shoplist shoplist : list) {
            Row row = sheet.createRow(cell);//从第二行开始保存数据
            row.createCell(0).setCellValue(cell);
            row.createCell(1).setCellValue(shoplist.getShopName());//将数据库的数据遍历出来
            row.createCell(2).setCellValue(String.valueOf(shoplist.getShopPrice()));
            row.createCell(3).setCellValue(String.valueOf(shoplist.getShopNum()));
            row.createCell(4).setCellValue(String.valueOf(shoplist.getShopType()));
            cell++;
        }
        return wb;
    }
}
